﻿using RpcClient.Helper;
using RpcClient.Interface;
using RpcClient.Tran.Tcc;

namespace RpcClient.Collect
{
    internal class RpcTccTranCollect : IRpcTccTranService
    {
        private readonly IUnityCollect _Unity;

        public RpcTccTranCollect(IUnityCollect unity)
        {
            _Unity = unity;
        }
        public void RegTran<T, TccEvent>(string name) where TccEvent : ITccEvent where T : class
        {
            if (!this._Unity.Register(typeof(IRpcTranEvent<T>), typeof(TccEvent), name))
            {
                return;
            }
            RpcTranCollect.RegTran(name, new TccTranTemplate<T>(name));
        }

        public void RegTran<T, TccEvent>() where TccEvent : ITccEvent where T : class
        {
            string name = TranHelper.GetTranName(typeof(T));
            this.RegTran<T, TccEvent>(name);
        }

        public void RegTran<TccEvent>(string name) where TccEvent : ITccEvent
        {
            if (!this._Unity.Register(typeof(IRpcTranEvent), typeof(TccEvent), name))
            {
                return;
            }
            RpcTranCollect.RegTran(name, new TccNoParamBasicTemplate(name));
        }

        public void RegNoParamTran<Extend, TccEvent>(string name) where TccEvent : ITccEvent
        {
            if (!this._Unity.Register(typeof(IRpcTranNoParamEvent<Extend>), typeof(TccEvent), name))
            {
                return;
            }
            RpcTranCollect.RegTran(name, new TccNoParamTemplate<Extend>(name));
        }

        public void RegTran<T, Extend, TccEvent>(string name)
            where T : class
            where TccEvent : ITccEvent
        {
            if (!this._Unity.Register(typeof(IRpcTranEvent<T, Extend>), typeof(TccEvent), name))
            {
                return;
            }
            RpcTranCollect.RegTran(name, new TccBasicTemplate<T, Extend>(name));
        }

        public void RegTran<T, Extend, TccEvent>()
            where T : class
              where TccEvent : ITccEvent
        {
            string name = TranHelper.GetTranName(typeof(T));
            this.RegTran<T, Extend, TccEvent>(name);
        }
    }
}
